package com.third.share.view;

import android.content.Context;
import android.support.annotation.Nullable;
import android.text.Layout;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * Created by Administrator on 2017-11-07.
 */
//com.third.share.view.ThirdShareItem
public class ThirdShareItem extends LinearLayout{
    private TextView tvShare;
    private ImageView imgShare;
    private float density = 1.0f;
    public ThirdShareItem(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.setOrientation(LinearLayout.VERTICAL);
        this.setGravity(Gravity.CENTER_HORIZONTAL);
        density = context.getResources().getDisplayMetrics().density;
        imgShare = new ImageView(context,attrs);
        LinearLayout.LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.bottomMargin = dpToPx(5);
        layoutParams.height = dpToPx(50);
        layoutParams.width = dpToPx(50);
        imgShare.setLayoutParams(layoutParams);
        this.addView(imgShare);
        tvShare = new TextView(context,attrs);
        layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
        tvShare.setTextColor(0xffffffff);
        tvShare.setGravity(Gravity.CENTER);
        tvShare.setLayoutParams(layoutParams);
        this.addView(tvShare);

    }

    public void setImagePic(int picId){
        imgShare.setImageResource(picId);
    }

    private int dpToPx(int dp){
        return (int)(dp*density+0.5);
    }
}
